Skip to content

core/desktopentry: add file system watcher for desktop entry directories #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

bbedward
Copy link

@bbedward bbedward commented Jul 14, 2025

DesktopEntries only scans one time~~, and doesnt expose scanning functions to QML. This adds a rescan function, a signal for applications changed. It just allows a nicer launcher that doesn't get stale.~~

This adds:

  • DesktopUtils which had a common function for locating .desktop files
  • DesktopEntryMonitor which implements QFileSystemWatcher
    • Watches the desktop entry target directories
  • Connect monitor to DesktopEntryManager and add a new signal applicationsChanged
    • On directory updated, it re-fetches the entries and emits the signal

@outfoxxed
Copy link
Member

outfoxxed commented Jul 14, 2025

I'm generally conflicted on this one because I prefer state change notifications to manually triggered scanning, which often leads to polling.

As I'm aware, similar GTK based tools usually listen to a signal provided by glib/gio for this. I've been planning to check what that does and implement it here if feasible, as an alternative to re-scanning. If you're interested in figuring it out, https://github.com/GNOME/glib/blob/6e2a31f97a345e0a6b57a0c5c9f9b7514d61b755/gio/gappinfo.c#L2010 is probably a good place to start.

Looks like its just a simple directory watch, but it likely has to be recursive on every potential desktop entry dir, otherwise it's unlikely to handle nix generation switches and such.

This is the general direction I'd like to take it in. No pressure on you to implement it if you don't want to.

@bbedward bbedward changed the title core: add rescan method to DesktopEntryManager core: add file system watcher for desktop entries Jul 15, 2025
@bbedward bbedward changed the title core: add file system watcher for desktop entries (wip) core: add file system watcher for desktop entries Jul 15, 2025
@bbedward bbedward changed the title (wip) core: add file system watcher for desktop entries (wip/donotmerge) core/desktopentry: add file system watcher for desktop entry directories Jul 15, 2025
@bbedward bbedward changed the title (wip/donotmerge) core/desktopentry: add file system watcher for desktop entry directories core/desktopentry: add file system watcher for desktop entry directories Jul 15, 2025
Copy link
Member

@outfoxxed outfoxxed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you've marked it as WIP. Partial review

@bbedward
Copy link
Author

@outfoxxed I addressed the comments, I had it initially watching .desktop files and then decided against it, to just watch the directories and rescan when there's a change instead.

Sorry for the confusion, not wip anymore - ready for review

@Purian23
Copy link

Would there be anything holding this one up for primetime? It will be quite useful.

Copy link
Member

@outfoxxed outfoxxed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional notes:

  • Please don't add useless comments
  • Please do scanning triggered by a change in another thread via QRunnable. The desktop entry scanner takes long enough to run that it may have a noticeable stutter on some systems without it.

@bbedward
Copy link
Author

Thanks for taking another look, I implemented DesktopEntryScanner QRunnable to handle the rescan in the background and addressed other comments.

@bbedward bbedward requested a review from outfoxxed July 21, 2025 19:40
Copy link
Member

@outfoxxed outfoxxed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't appear to handle anything above the applications folder in the path being swapped out

@bbedward bbedward requested a review from outfoxxed July 26, 2025 15:31
Copy link
Member

@outfoxxed outfoxxed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this one has required a lot of re-review. Hopefully we're near done.

for (const auto& subdir: subdirs) this->watcher.addPath(subdir.absoluteFilePath());
}

void DesktopEntryMonitor::onDirectoryChanged(const QString&) { this->debounceTimer.start(); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately once we include parents it becomes more complex than this. Ideally we don't want to trigger a rescan if a user creates a file in / or something. However this is acceptable for now because fixing it properly will require rewriting QFileSystemWatcher.

@bbedward
Copy link
Author

Think I addressed all of the ones from this round @outfoxxed hopefully good now 🤞

@bbedward bbedward requested a review from outfoxxed July 26, 2025 22:11
@outfoxxed
Copy link
Member

missed the collapsed ones?

@bbedward
Copy link
Author

missed the collapsed ones?

yep, just addressed them - hopefully good now for real 🤦

bbedward added 6 commits July 27, 2025 18:24
De-dupe code paths to scanAndWatch function, Optimize lookups by using a
QSet, remove paths from watcher if deleted
- Create less fs watchers
- Just re-scan when a directory containing .desktop files changes
Copy link
Member

@outfoxxed outfoxxed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've received a report that this patch also duplicates the desktop entry list in rare cases, though I didn't see anything that would obviously cause that.
Apologies for the long review turnaround as well, I've been away for the last couple weeks.

@bbedward
Copy link
Author

Haven't seen the entries get duplicated myself , addressed the latest round of comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants